例7.2
#include<bits/stdc++.h>
using namespace std;

const int MAXN=1000;
struct JavaBean{
    double weight;
    double cost;
};

JavaBean arr[MAXN];

int Compare(JavaBean x,JavaBean y){
    return x.weight/x.cost>y.weight/y.cost;
}
//贪心
int main(){
    int n,m;
    while(scanf("%d%d",&m,&n)!=EOF){
        if(n==-1&&m==-1){
            break;
        }
        for(int i=0;i<n;++i){
            scanf("%lf%lf",&arr[i].weight,&arr[i].cost);
        }
        sort(arr,arr+n,Compare);//性价比排序
        double answer=0;
        for(int i=0;i<n;i++){
            if(m>=arr[i].cost){
                m-=arr[i].cost;
                answer+=arr[i].weight;
            }else{
                answer+=arr[i].weight*m/(arr[i].cost);
                m=0;
                break;
            }
        }
        printf("%.3lf\n",answer);
    }
    return 0;
}
